package com.gzyj.jtt808.v2013.protocol.jtt1078;

import cn.hutool.core.collection.CollectionUtil;
import com.gzyj.jtt808.v2011.protocol.jtt1078.JTT808_0x1205_AVResouces;
import com.gzyj.jtt808.v2013.Package;
import com.gzyj.jtt808.v2013.enums.BusinessDataType;
import io.netty.buffer.ByteBuf;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
@ApiModel("终端上传音视频资源列表")
public class JTT808_0x1205 extends Package implements Serializable {

    @ApiModelProperty("流水号")
    public Integer MsgNum;

    @ApiModelProperty("音视频资源列表")
    public List<JTT808_0x1205_AVResouces> AVResouces;

    public JTT808_0x1205(){
        super(BusinessDataType.终端上传音视频资源列表.getCode());
    }



    @Override
    public void encodeImpl(ByteBuf buf) {
        buf.writeShort(this.MsgNum);
        if(CollectionUtil.isNotEmpty(this.AVResouces)){
            buf.writeInt(this.AVResouces.size());
            for (JTT808_0x1205_AVResouces avResouces:this.AVResouces){
                avResouces.encode(buf);
            }
        }
    }

    @Override
    public JTT808_0x1205 decodeImpl(ByteBuf buf) {
        this.MsgNum=buf.readUnsignedShort();
        long len=buf.readUnsignedInt();
        this.AVResouces=new ArrayList<>();
        for (int i = 0; i < len; i++) {
            JTT808_0x1205_AVResouces avResouces=new JTT808_0x1205_AVResouces();
            avResouces.decode(buf);
            this.AVResouces.add(avResouces);
        }

        return this;
    }

}
